﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchoolLibrary.Entity.Person;
using SchoolLibrary.DataBase.DAO;
using SchoolLibrary.Desktop.Guide.Input;

namespace SchoolLibrary.Desktop.Guide
{
    public class ClassLeaderGuideForm : GuideForm<ClassLeader>
    {

        private string[] COLUMN_NAMES = { "id", "Фамилия", "Имя", "Отчество" };

        public ClassLeaderGuideForm() : base() { }

        protected override void addButton_Click(object sender, EventArgs e)
        {
            ClassLeaderInputDialog dialog = new ClassLeaderInputDialog();
            dialog.ShowDialog();
            ClassLeader classLeader = dialog.ClassLeader;
            if (classLeader != null)
            {
                ClassLeaderDAO.getInstance().save(classLeader);
                this.initData();
            }
        }

        protected override void editButton_Click(object sender, EventArgs e)
        {
            long id = getSelectedRowId();
            ClassLeader selectedСlassLeader = findById(id);
            ClassLeaderInputDialog dialog = new ClassLeaderInputDialog(selectedСlassLeader);
            dialog.ShowDialog();
            ClassLeader classLeader = dialog.ClassLeader;
            if (classLeader != null)
            {
                ClassLeaderDAO.getInstance().save(classLeader);
                this.initData();
            }
        }

        protected override void deleteButton_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        protected override string[] getColumnNames()
        {
            return COLUMN_NAMES;
        }

        protected override List<ClassLeader> findAll()
        {
            return ClassLeaderDAO.getInstance().findAll();
        }

        protected override ClassLeader findById(long id)
        {
            return ClassLeaderDAO.getInstance().findById(id);
        }

        protected override object[] createRow(ClassLeader classLeader)
        {
            List<object> row = new List<object>();
            row.Add(classLeader.Id);
            row.Add(classLeader.Surname);
            row.Add(classLeader.Name);
            row.Add(classLeader.MiddleName);
            return row.ToArray();
        }
    }
}
